import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression

# 生成一些示例数据
x = np.array([1, 2, 3, 4, 5]).reshape(-1, 1)
y = np.array([2, 4, 6, 8, 10])

# 创建线性回归模型
model = LinearRegression()
model.fit(x, y)

# 预测新数据
new_x = np.array([6]).reshape(-1, 1)
prediction = model.predict(new_x)
print(f"预测值: {prediction[0]}")

# 绘制数据和拟合直线
plt.scatter(x, y)
plt.plot(x, model.predict(x), color='red')
plt.show()